// 添加聊天记录请求参数
import {request} from "@/apis/request.ts";
const token = localStorage.getItem("token");

export interface ChatMessageParams {
    messageId?: number;
    chatId?: number;
    sender?: string;
    content?: string;
    type?: string;
}

export interface ChatMessageData {
    messageId: number;
    chatId: number;
    sender: string;
    content: string;
    type: string;
}

// 接口返回结构
export interface ChatMessageRes<T> {
    code: number;
    message: string;
    data: T;
}

const getChatMessagesByChatId = async (chatId: number): Promise<ChatMessageRes<ChatMessageData[]>> => {
    const token = localStorage.getItem("token");
    return request<ChatMessageRes<ChatMessageData[]>>(`/api/chat-messages/${chatId}`, {
        method: 'GET',
        headers: {
            Authorization: `Bearer ${token}`,
        }
    });
}
const deleteChatMessageByChatId = async (chatId: number): Promise<number> => {
    const token = localStorage.getItem("token");
    return request<number>(`/api/chat-messages/${chatId}`, {
        method: 'DELETE',
        headers: {
            Authorization: `Bearer ${token}`,
        },
    });
}
const addChatMessage = async (params: ChatMessageParams): Promise<ChatMessageData> => {
    const token = localStorage.getItem("token");
    return request<ChatMessageData>(`/api/chat-messages/addChatMessage`, {
        method: 'POST',
        headers: {
            Authorization: `Bearer ${token}`,
        },
        data: params,
    });
}
export {
    getChatMessagesByChatId,
    deleteChatMessageByChatId,
    addChatMessage
}